package main


import "fmt"
import "io/ioutil"
import ."compiler/lexer"


func main() {

	data, err := ioutil.ReadFile("test.lua")

	if err != nil {
		panic("err")
	}

	testLexer(string(data), "test.lua")

}


func testLexer(chunk, chunkName string) {

	lexer := NewLexer(chunk, chunkName)

	for {
		line, kind, token := lexer.NextToken()

		fmt.Printf("[%02d] [%-10s] %s\n", line, kindOfCategory(kind), token)

		if kind == TOKEN_EOF {
			break
		}
	}

}


func kindOfCategory(kind int) string {

	switch {
		case kind < TOKEN_SEP_SEMI:	return "other"

		case kind <= TOKEN_SEP_RCURLY:	return "seperator"

		case kind <= TOKEN_OP_NOT:	return "operator"

		case kind <= TOKEN_KW_WHILE:	return "keyword"

		case kind == TOKEN_IDENTIFIER:	return "identifier"

		case kind == TOKEN_NUMBER:	return "number"

		case kind == TOKEN_STRING:	return "string"

		default:					return "other"
	}

}